﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;
using Groundwork.Extensions;
using System.IO;
using System.Security;

namespace Test.Groundwork.Extensions
{
    [TestClass]
    public class IOTests
    {
        [TestInitialize]
        public void Setup()
        {
            if (File.Exists(Path.Combine(Environment.CurrentDirectory,"test.txt")))
            { 
                File.Delete(Path.Combine(Environment.CurrentDirectory,"test.txt"));
            }
        }

        [TestMethod]
        public void TestStringToFileSave()
        {
            string target = "hello world";
            target.SaveToFile(Environment.CurrentDirectory, "test.txt");
            File.Exists(Path.Combine(Environment.CurrentDirectory,"test.txt")).Should().BeTrue();
        }

        [TestMethod]
        [ExpectedException(typeof(IOException))]
        public void TestFileWriteFailureOverwriteFile()
        {
            string target = "hello world";
            target.SaveToFile(Environment.CurrentDirectory, "test.txt");
            target.SaveToFile(Environment.CurrentDirectory, "test.txt");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestFileNullPathException()
        {
            string target = "hello world";
            target.SaveToFile(null, "test.txt");
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestFileNullFileNameException()
        {
            string target = "hello world";
            target.SaveToFile("",null);
        }


        [TestMethod]        
        public void TestBuildPath()
        {
            string target = Path.Combine(Environment.CurrentDirectory,"test1");
            target.BuildPath();
            Directory.Exists(target).Should().BeTrue();
            Directory.Delete(target);
        }

    }
}
































